package expansion.applicationListener;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.*;
import org.springframework.stereotype.Component;

/**
 * https://blog.csdn.net/f641385712/article/details/105762050
 */
@Component
public class MyApplicationListener implements ApplicationListener<MyEvent> {

    /**
     * 当容器中发布此事件以后，方法触发
     */
    @Override
    public void onApplicationEvent(MyEvent event) {
        System.out.println("收到事件：" + event);
    }

    @EventListener(classes = {ApplicationEvent.class})
    public void onApplicationEvent2(ApplicationEvent event) {
        System.out.println(event.getSource() + "====" + event.getTimestamp());
    }

    @EventListener(classes = {ContextRefreshedEvent.class})
    public void a() {
        System.out.println("ContextRefreshedEvent");
    }

    @EventListener(classes = {ContextStartedEvent.class})
    public void b() {
        System.out.println("ContextStartedEvent");
    }

    @EventListener(classes = {ContextStoppedEvent.class})
    public void c() {
        System.out.println("ContextStoppedEvent");
    }

    @EventListener(classes = {ContextClosedEvent.class})
    public void d() {
        System.out.println("ContextClosedEvent");
    }

    @EventListener(classes = {ApplicationContextEvent.class})
    public void e() {
        System.out.println("ApplicationContextEvent");
    }
}